<template>
  <div>
    <h2>体校类别</h2>
    <canvas ref="chartCanvas"></canvas>
  </div>
</template>

<script>
import Chart from "chart.js/auto";

export default {
  name: "ChartComponent",
  data() {
    return {
      chartData: {
        labels: ["省级", "地市级", "县级"],
        datasets: [
          {
            label: "全国体校数量/所",
            data: [34201, 9285, 4257],
            backgroundColor: [
              "rgba(54, 162, 235, 0.2)",
              "rgba(255, 206, 86, 0.2)",
              "rgba(75, 192, 192, 0.2)"
            ],
            borderColor: [
              "rgba(54, 162, 235, 1)",
              "rgba(255, 206, 86, 1)",
              "rgba(75, 192, 192, 1)"
            ],
            borderWidth: 1
          }
        ]
      },
      chartOptions: {
        scales: {
          y: {
            beginAtZero: true
          }
        }
      }
    };
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      new Chart(this.$refs.chartCanvas, {
        type: "bar",
        data: this.chartData,
        options: this.chartOptions
      });
    }
  }
};
</script>

<style scoped>
canvas {
  width: 100%;
  height: 300px;
}
</style>
